<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 商品模块
 * 
 * @author  : $Author: spike $
 * @date    : $Date: 2014-03-03 17:00:52 +0800 (一, 2014-03-03) $
 * @version : $Id: coolpowder.php 52 2014-03-03 09:00:52Z spike $
 * @rev     : $Revision: 52 $
 */
class Coolpowder extends MY_Controller 
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $this->load->dao('Comment_dao');
        $comment = $this->Comment_dao->get(
            array(
                'status' => COMMENT_STATUS_ON,
            ),
            array(
                'nickname','comment','create_time'
            ),
            '`create_time` DESC'
        );
        $data = array(
            'current_url' => DOMAIN.'coolpowder',
            'comment'     => $comment,
        );
        $this->load->view('home/header.tpl', $data);
        $this->load->view('coolpowder/index.tpl');
        $this->load->view('home/footer.tpl');
    }

    public function comment()
    {
        if($this->input->is_post_request())
        {
            $params = $this->input->post();

            temp('add_comment', $params);

            $this->load->model('Home_model');

            if( FALSE === $this->Home_model->add_comment($params) )
            {
                show_error($this->Home_model->get_error());
            }
            temp('add_comment', NULL);

            $data = array(
                'current_url' => DOMAIN.'comment',
                'temp'        => temp('add_comment'),
            );
            $this->load->view('home/header.tpl', $data);
            $this->load->view('coolpowder/comment_success.tpl');
            $this->load->view('home/footer.tpl');
        }
        else
        {
            $data = array(
                'current_url' => DOMAIN.'comment',
                'temp'        => temp('add_comment'),
            );
            $this->load->view('home/header.tpl', $data);
            $this->load->view('coolpowder/comment.tpl');
            $this->load->view('home/footer.tpl');
        }
    }

    public function wallpaper()
    {  
        $data = array(
            'js'        => array(
                                'jquery/jquery.jcarousel.min.js',
                                'wallpaper.js'
                            ),
            'wallpaper' => $this->config->item('wallpaper'),
            'current_url' => DOMAIN.'coolpowder',
        );
        $this->load->view('home/header.tpl', $data);
        $this->load->view('coolpowder/wallpaper.tpl');
        $this->load->view('home/footer.tpl');
    }
}